export function getMonthDetails(dateString) {
  const [year, month] = dateString.split('-').map(Number);

  // 获取上一个月的最后一天
  const prevMonthLastDay = new Date(year, month - 1, 0).getDate();
  // 获取当前月的最后一天
  const currentMonthLastDay = new Date(year, month, 0).getDate();
  // 获取下一个月的最后一天
  const nextMonthLastDay = new Date(year, month + 1, 0).getDate();

  // 初始化数组来存储日期详情
  const prevMonthDays = [];
  const currentMonthDays = [];
  const nextMonthDays = [];

  // 获取上一个月的日期详情
  for (let i = 1; i <= prevMonthLastDay; i++) {
    const date = new Date(year, month - 2, i);
    const dayOfWeek = date.toLocaleDateString('zh-CN', { weekday: 'long' });
    prevMonthDays.push({ date: i, dayOfWeek, week: date.getDay(), month: month - 1, year });
  }

  // 获取当前月的日期详情
  for (let i = 1; i <= currentMonthLastDay; i++) {
    const date = new Date(year, month - 1, i);
    const dayOfWeek = date.toLocaleDateString('zh-CN', { weekday: 'long' });
    currentMonthDays.push({ date: i, dayOfWeek, week: date.getDay(), month, year });
  }

  // 获取下一个月的日期详情
  for (let i = 1; i <= nextMonthLastDay; i++) {
    const date = new Date(year, month, i);
    const dayOfWeek = date.toLocaleDateString('zh-CN', { weekday: 'long' });
    nextMonthDays.push({ date: i, dayOfWeek, week: date.getDay(), month: month + 1, year });
  }

  return {
    prevMonthDays,
    currentMonthDays,
    nextMonthDays,
  };
}


export function getNowDay(_mouth) {
  const now = _mouth ? new Date(_mouth.replace(/-/g, "/")) : new Date();
  return {
    year: now.getFullYear(),
    month: now.getMonth() + 1,
    date: now.getDate(),
  }
}

// date 代表指定的日期，格式：2018-09-27
export function getNextDate(date, day = 1) {
  const dd = new Date(date.replace(/-/g, "/"));
  dd.setDate(dd.getDate() + day);
  return {
    year: dd.getFullYear(),
    month: dd.getMonth() + 1,
    date: dd.getDate(),
  }
};